package cn.tedu.ivos.user.controller;
import cn.tedu.ivos.base.handler.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQueryParam;
import cn.tedu.ivos.user.pojo.dto.UserSavaParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 用户登录
     * POST http://localhost:8080/v1/user/login?username=admin&password=admin
     * @param userLoginParam
     * @return
     */
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录:userLoginParam={}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }
    @PostMapping("/save")
    public JsonResult saveUser(UserSavaParam userSaveParam){
        log.debug("保存用户:userSaveParam={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("/select")
    public JsonResult selectUser(UserQueryParam userQuery){
        log.debug("查询用户：userQuery={}",userQuery);
        List<UserVO>list=userService.selectUserList(userQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("/update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("重置密码：uesrId={}",userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }
    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(
            @PathVariable Long userId,@PathVariable String status){
        log.debug("更新用户状态:userId={},status={}",userId,status);
        userService.updateStatus(userId,status);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除用户:userId={}",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }

}